package com.example.application;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private TextView uid;
    private Button cc;
    private Button jI;
    private Button jLF;
    private Button jC;
    private int times = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        final View viewDialog = LayoutInflater.from(MainActivity.this).inflate(R.layout.custondialog, null, false);
        builder.setTitle("登录框").setView(viewDialog).setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                EditText uid = viewDialog.findViewById(R.id.user_id);
                EditText upw = viewDialog.findViewById(R.id.user_password);
                if (uid.getText().toString().equals("abc") && upw.getText().toString().equals("123")) {
                    Toast.makeText(MainActivity.this, "成功UserID:" + uid.getText().toString()
                            + "Password+" + upw.getText().toString(), Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(MainActivity.this, "失败WRONG", Toast.LENGTH_LONG).show();
                }
            }
        }).setNegativeButton("退出", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                finish();
            }
        });
        builder.create().show();
        uid = findViewById(R.id.uid);
        cc = findViewById(R.id.cc);
        jI = findViewById(R.id.jumpToIntentDemo);
        jLF = findViewById(R.id.toLF);
        jC = findViewById(R.id.toChat);
        Intent bI = getIntent();
        times = bI.getIntExtra("cTimes", 0);
        if (times % 2 != 0) {
            uid.setText("Hello World" + times);
        } else {
            uid.setText("Surprise MotherFucker" + times);
        }
        cc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                times++;
                if (times % 2 != 0) {
                    uid.setText("Hello World" + times);
                } else {
                    uid.setText("Surprise MotherFucker" + times);
                }
            }
        });

        jI.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, IntentDemoActivity.class);
                intent.putExtra("times", times);
                startActivity(intent);
                finish();
            }
        });

        jLF.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, LifeCycleActivity.class);
                startActivity(intent);
                finish();
            }
        });

        jC.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, RecyclerViewDemoActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }
}
